package com.jj.conterllor;

import com.jj.annotatiion.Role;
import com.jj.entity.userlogin;
import com.jj.service.userservice;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/u")
public class UserLoginController {

    @Resource
   private userservice userservice;

    //登录-----------------------------------------
    @RequestMapping("toLogin")
    public String toLogin(){
        return "login";
    }
    @RequestMapping("login")
    public String login(userlogin u, ModelMap model){
        List<userlogin> userlogins = userservice.selectAll();
        model.addAttribute("uls",userlogins);
        boolean flag = userservice.login(u);
        if (flag){
            return "ulselect";
        }
        return "/ultoerror";
    }
    //登陆失败
    @RequestMapping("ultoerror")
    public String ero(){
        return "forward:toLogin";
    }
    //添加数据--------------------------------------
    @RequestMapping("a")
    public String dd(){
        return "ulinsert";
    }
    @RequestMapping("ulinsert")
    public String inserttj(userlogin ul){
        userservice.inserttj(ul);
        return "forward:login";
    }

    //修改数据---------------------------------------
    @RequestMapping("xg")
    public String aa(Model model, int user_id){
        model.addAttribute("uid",user_id);

        return "ulupdate";
    }
    @RequestMapping("ulupdate")
    public String xiugia(userlogin un){
        userlogin us = new userlogin();
        us.setUser_id(un.getUser_id());
        us.setLogin_name(un.getLogin_name());
        us.setLogin_paw(un.getLogin_paw());
        userservice.updatexg(us);
        return "forward:login";
    }
    //删除数据---------------------------------------
    @RequestMapping("delete")

    public String shan(int user_id){
        userservice.deletesc(user_id);
        return "forward:login";
    }
    //权限拦截
    @RequestMapping("t1")
    @ResponseBody
    @Role("QXGL")
    public String t1(){
        return"OK";
    }
    @RequestMapping("t2")
    public String t2(){
        return"1";
    }
    //多数据源
//    @RequestMapping("d1")
//    public String d1(){
//        List<user0> getmy = userservice.getmy();
//        List<user0> getmy1 = userservice.getmy1();
//        List<user0> getmy2 = userservice.getmy2();
//        System.out.println(getmy);
//        System.out.println(getmy1);
//        System.out.println(getmy2);
//        return"2";
//    }
}